<template>
	<view class="content">
		<view class="input-block">
			<view class="input-left">
				<input placeholder="请输入关键字" v-model="keyword" @confirm="search" placeholder-style="color: #AAAAAA" />
			</view>
			<view class="search" @click="getList(true)">搜索</view>
		</view>
		<template v-if="list.length>0">
			<PositionItem :key="item.id" :data="item" v-for="(item) in list"></PositionItem>
		</template>
		<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
		<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import PositionItem from "@/page_other/job_hunting/recruit_list/index.vue";
	import {
		getPublishApi
	} from '@/api/job_hunting.js';
	export default {
		components: {
			PositionItem
		},
		data() {
			return {
				list: [],
				conf: {
					page: 1,
					limit: 10
				},
				more: true,
				keyword: ''
			}
		},
		methods: {
			refresh() {
				this.conf.page = 1
				this.more = true
				this.getList(true);
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getPublishApi({
					page: this.conf.page,
					limit: this.conf.limit,
					keyword: this.keyword
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.total)
				})
			}
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad() {
			this.getList(true)
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 30rpx;

		.input-block {
			display: flex;
			border-radius: 50px;
			align-items: center;
			background-color: #FFFFFF;
			justify-content: space-between;
			width: 100%;
			height: 70rpx;
			margin: auto;
			padding: 0 10rpx 0 20rpx;
			margin-bottom: 30rpx;

			.input-left {
				width: calc(100% - 140rpx);
				display: flex;

				input {
					border-radius: 50px;
					width: 100%;
					font-size: 28rpx;
					color: #767676;
				}
			}

			.search {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 120rpx;
				border-radius: 50rpx;
				height: 55rpx;
				padding-bottom: 5rpx;
				color: #FFFFFF;
				background: linear-gradient(90deg, #1C89FD 0%, #22DDE8 100%);
				font-size: 28rpx;
			}
		}
	}
</style>